package lev01_beginnerClass.class04_randToRand;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * use funcion generating 0 wiht p and 1 with 1-p  to write a new function generating 0 and 1 with equal probality
 */
public class L03_Rand01ToRand01 {


    public static void main(String[] args) {
        int[] count = new int[2];
        for(int i = 0 ;i < 100000;i++){
            count[f01fair()]++;
        }
        System.out.println(Arrays.toString(count));
    }

    public static int f01fair(){
        int ans = 0;
        do {
            ans = f01unfair();
        }while (ans == f01unfair());
        return ans;
    }

    /**
     * 0 and 1 with unequal probablity;
     * @return
     */
    public static int f01unfair(){
        return Math.random() <0.8? 0:1;
    }
}
